// Para class : Prefs

package appPref;

import java.awt.Image;
import java.util.Locale;
import java.util.ResourceBundle;
import java.util.MissingResourceException;
import javax.swing.ImageIcon;
import java.net.URL;

public class Para {

  private static Para para;

  private Locale locale;
  private ResourceBundle interStringDispenser;

  {
    try {
      locale = Locale.FRENCH;
      //locale = Locale.ENGLISH;
      interStringDispenser = ResourceBundle.getBundle("appPref.StringRes", locale);
    }
    catch (Exception e) {
      System.out.println(e.getMessage());
    }
  }

  public Para() {
    super();
  }

  public static Para getPara() {
    if (para == null) {
      para = new Para();
    }
    return para;
  }

  public String getT(String key) {
    String lookFor = null;
    try {
      lookFor = interStringDispenser.getString(key);
    }
    catch (MissingResourceException e) {
      System.out.println(e.getMessage() + " // Missing string: " + key);
      lookFor = "Missing string: " + key;
    }
    return lookFor;
  }

  public ImageIcon getImageIcon(String anImage) {
    URL url = null;
    ImageIcon imageIcon = null;
    try {
      url = this.getClass().getResource(anImage);
      imageIcon = new ImageIcon(url);
    }
    catch (Exception e) {
      System.out.println(e.getMessage() + " // no URL");
    }
    return imageIcon;
  }

  public Image getImage(String anImage) {
    URL url = null;
    Image image = null;
    ImageIcon imageIcon = this.getImageIcon(anImage);
    if (imageIcon != null) {
      image = imageIcon.getImage();
    }
    return image;
  }

}
